package com.neolix.watch.weather;

import android.content.Context;
import android.util.Log;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.neolix.watch.service.BackgroundTaskBase;

import org.joda.time.DateTime;

import static com.baidu.location.LocationClientOption.LocationMode;
import static com.neolix.watch.NeolixApplication.getInstance;

public class UpdateLocationTask extends BackgroundTaskBase {
    public UpdateLocationTask(Context applicationContext) {
        super(applicationContext);
    }

    @Override
    public void execute() {
        //1.get Latitude and longitude
        Log.i("BaiduLocationApiDem", "开始进行定位" + DateTime.now());

        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationMode.Battery_Saving);
        option.setCoorType("gcj02");
        option.setNeedDeviceDirect(true);
        option.setIsNeedAddress(true);

        LocationClient mLocClient = (getInstance()).locationClient;
        if (mLocClient == null) {
            getInstance().initLocation();
            return;
        }

        mLocClient.setLocOption(option);

        mLocClient.start();
        mLocClient.requestLocation();
    }
}
